<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Studenten</title>
    <f:metadata>
        <f:event listener="#{loginBean.verifyUseLogin}" type="preRenderView">
        </f:event>
    </f:metadata>
</h:head>
<h:body>
    <ui:composition template="menutemp.xhtml">
        <h:form id="data">
            <p:growl id="growl" showDetail="true" autoUpdate="true" life="10000" />
            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton type="button" value="Neu" actionListener="#{studentenBean.clearStudentdata}"
                        icon="ui-icon-document" onclick="dlg.show()" update=":dia1" />
                    <p:commandButton id="import" value="Import Excel" actionListener="#{studentenBean.importExcel}"
                        icon="ui-icon-folder-open" update="data" />
                    <p:menuButton value="Export">
                    </p:menuButton>
                    <p:commandButton id="randomStudents" value="Random Students"
                        actionListener="#{studentenBean.populate}" icon="ui-icon-comment" update="data" />
                    <p:menuButton value="Delete" icon="ui-icon-trash">
                        <p:menuitem id="deleteAll" value="All" actionListener="#{studentenBean.deleteAll}"
                            icon="ui-icon-trash" update="data" />
                        <p:menuitem id="deleteSelected" value="Selected"
                            actionListener="#{studentenBean.deleteSelected}" icon="ui-icon-trash" update="data" />
                    </p:menuButton>
                </p:toolbarGroup>
            </p:toolbar>
            <p:contextMenu for="dataTable">
                <p:menuitem value="Bearbeiten" icon="ui-icon-search" actionListener="#{studentenBean.bearbeiteSelected}"
                    onclick="dlg2.show()" update=":dia2" />
                <p:menuitem value="Delete" update="data" icon="ui-icon-trash"
                    actionListener="#{studentenBean.deleteSelected}" />
            </p:contextMenu>
            <p:dataTable id="dataTable" var="student" value="#{studentenBean.studenten}" rowKey="#{student.pruefnr}"
                selection="#{studentenBean.selectedStudents}" selectionMode="multiple" paginator="true" rows="10"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rowsPerPageTemplate="10,20,30" emptyMessage="Keine Studenten mit angegebenen Kriterien gefunden"
                filteredValue="#{studentenBean.filteredStudents}">
                <f:facet name="header">  
                    Studenten 
                </f:facet>
                <p:column id="pruefnrHeader" sortBy="#{student.pruefnr}" filterBy="#{student.pruefnr}"
                    filterMatchMode="exact">
                    <f:facet name="header">
                        <h:outputText value="Prüfnr." />
                    </f:facet>
                    <h:outputText value="#{student.pruefnr}" />
                </p:column>

                <p:column sortBy="#{student.vorname}" filterBy="#{student.vorname}" filterMatchMode="contains">
                    <f:facet name="header">
                        <h:outputText value="Vorname" />
                    </f:facet>
                    <h:outputText value="#{student.vorname}" />
                </p:column>

                <p:column sortBy="#{student.nachname}" filterBy="#{student.nachname}" filterMatchMode="contains">
                    <f:facet name="header">
                        <h:outputText value="Nachname" />
                    </f:facet>
                    <h:outputText value="#{student.nachname}" />
                </p:column>
                <p:column sortBy="#{student.firma}" filterBy="#{student.firma}" filterMatchMode="contains">
                    <f:facet name="header">
                        <h:outputText value="Firma" />
                    </f:facet>
                    <h:outputText value="#{student.firma}" />
                </p:column>
                <p:column sortBy="#{student.ort}" filterBy="#{student.ort}" filterMatchMode="contains">
                    <f:facet name="header">
                        <h:outputText value="Ort" />
                    </f:facet>
                    <h:outputText value="#{student.ort}" />
                </p:column>
                <p:column sortBy="#{student.beruf}" filterBy="#{student.beruf}"
                    filterOptions="#{studentenBean.berufOptions}" filterMaxLength="50" filterMatchMode="contains">
                    <f:facet name="header">
                        <h:outputText value="Beruf" />
                    </f:facet>
                    <h:outputText value="#{student.beruf}" />
                </p:column>
                <p:column headerText="BBS" filterBy="#{student.bbs}" filterMatchMode="contains">
                    <h:outputText value="#{student.bbs}" />
                </p:column>
            </p:dataTable>
        </h:form>
        <p:dialog header="Studenten Daten eingeben" id="dialog1" widgetVar="dlg" resizable="false" width="455">
            <h:form id="dia1" dynamic="true">
                <h:panelGrid columns="2" style="margin-bottom:10px">
                    <h:outputLabel for="pruefnr" value="Prüfnr.:" />
                    <p:inputText id="pruefnr" value="#{studentenBean.pruefnr}" size="35" />
                    <h:outputLabel for="firstname" value="Vorname:" />
                    <p:inputText id="firstname" value="#{studentenBean.newVorname}" size="35" />
                    <h:outputLabel for="nachname" value="Nachname:" />
                    <p:inputText id="nachname" value="#{studentenBean.newNachname}" size="35" />
                    <h:outputLabel for="firma" value="Firma:" />
                    <p:inputText id="firma" value="#{studentenBean.newFirma}" size="35" />
                    <h:outputLabel for="ort" value="Ort:" />
                    <p:inputText id="ort" value="#{studentenBean.newOrt}" size="35" />
                    <h:outputLabel for="beruf" value="Beruf:" />
                    <p:inputText id="beruf" value="#{studentenBean.newBeruf}" size="35" />
                    <h:outputLabel for="bbs" value="BBS:" />
                    <p:inputText id="bbs" value="#{studentenBean.newbbs}" size="35" />
                </h:panelGrid>
                <p:commandButton id="submitButton" value="Submit" actionListener="#{studentenBean.submit}"
                    update=":data" oncomplete="dlg.hide();" />
            </h:form>
        </p:dialog>
        <p:dialog header="Studenten Daten bearbeiten" id="dialog2" widgetVar="dlg2" resizable="false" width="455">
            <h:form id="dia2" dynamic="true">
                <h:panelGrid columns="2" style="margin-bottom:10px">
                    <h:outputLabel for="pruefnr2" value="Prüfnr.:" />
                    <p:inputText id="pruefnr2" value="#{studentenBean.pruefnr}" size="35" />
                    <h:outputLabel for="firstname2" value="Vorname:" />
                    <p:inputText id="firstname2" value="#{studentenBean.newVorname}" size="35" />
                    <h:outputLabel for="nachname2" value="Nachname:" />
                    <p:inputText id="nachname2" value="#{studentenBean.newNachname}" size="35" />
                    <h:outputLabel for="firma2" value="Firma:" />
                    <p:inputText id="firma2" value="#{studentenBean.newFirma}" size="35" />
                    <h:outputLabel for="ort2" value="Ort:" />
                    <p:inputText id="ort2" value="#{studentenBean.newOrt}" size="35" />
                    <h:outputLabel for="beruf2" value="Beruf:" />
                    <p:inputText id="beruf2" value="#{studentenBean.newBeruf}" size="35" />
                    <h:outputLabel for="bbs2" value="BBS:" />
                    <p:inputText id="bbs2" value="#{studentenBean.newbbs}" size="35" />
                </h:panelGrid>
                <p:commandButton id="submitButton2" value="Update" actionListener="#{studentenBean.updateStudent}"
                    update=":data" oncomplete="dlg2.hide();" />
            </h:form>
        </p:dialog>
    </ui:composition>
</h:body>
</html>